<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Connecting to MS SQL Server and SQL Azure databases</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.pdo-sqlsrv.html">« MS SQL Server (PDO)</a></li>
      <li style="float: right;"><a href="ref.pdo-oci.html">Oracle (PDO) »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pdo-sqlsrv.html">MS SQL Server (PDO)</a></li>
    <li>Connecting to MS SQL Server and SQL Azure databases</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ref.pdo-sqlsrv.connection" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">PDO_SQLSRV DSN</h1>
    <p class="verinfo">(PECL pdo_sqlsrv &gt;= 2.0.1)</p><p class="refpurpose"><span class="refname">PDO_SQLSRV DSN</span> &mdash; <span class="dc-title">Connecting to MS SQL Server and SQL Azure databases</span></p>

   </div>

   <div class="refsect1 description" id="refsect1-ref.pdo-sqlsrv.connection-description">
    <h3 class="title">说明</h3>
    <p class="para">
     The PDO_SQLSRV Data Source Name (DSN) is composed of the following elements:
     <dl>
      
       <dt>
DSN prefix</dt>

       <dd>

        <p class="para">
        The DSN prefix is <strong class="userinput"><code>sqlsrv:</code></strong>.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">APP</code></dt>

       <dd>

        <p class="para">
         The application name used in tracing.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">ConnectionPooling</code></dt>

       <dd>

        <p class="para">
         Specifies whether the connection is assigned from a connection pool 
         (1 or <strong><code>true</code></strong>) or not (0 or <strong><code>false</code></strong>).
        </p>
       </dd>

      
      
       <dt>
<code class="literal">Database</code></dt>

       <dd>

        <p class="para">
         The name of the database.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">Encrypt</code></dt>

       <dd>

        <p class="para">
         Specifies whether the communication with SQL Server is encrypted 
         (1 or <strong><code>true</code></strong>) or unencrypted (0 or <strong><code>false</code></strong>).
        </p>
       </dd>

      
      
       <dt>
<code class="literal">Failover_Partner</code></dt>

       <dd>

        <p class="para">
         Specifies the server and instance of the database&#039;s mirror (if enabled 
         and configured) to use when the primary server is unavailable.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">LoginTimeout</code></dt>

       <dd>

        <p class="para">
         Specifies the number of seconds to wait before failing the connection attempt.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">MultipleActiveResultSets</code></dt>

       <dd>

        <p class="para">
         Disables or explicitly enables support for multiple active Result sets (MARS).
        </p>
       </dd>

      
      
       <dt>
<code class="literal">QuotedId</code></dt>

       <dd>

        <p class="para">
         Specifies whether to use SQL-92 rules for quoted identifiers (1 or <strong><code>true</code></strong>) 
         or to use legacy Transact-SQL rules (0 or <strong><code>false</code></strong>).
        </p>
       </dd>

      
      
       <dt>
<code class="literal">Server</code></dt>

       <dd>

        <p class="para">
         The name of the database server.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">TraceFile</code></dt>

       <dd>

        <p class="para">
         Specifies the path for the file used for trace data.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">TraceOn</code></dt>

       <dd>

        <p class="para">
         Specifies whether ODBC tracing is enabled (1 or <strong><code>true</code></strong>) or disabled 
         (0 or <strong><code>false</code></strong>) for the connection being established.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">TransactionIsolation</code></dt>

       <dd>

        <p class="para">
         Specifies the transaction isolation level. The accepted values for this 
         option are PDO::SQLSRV_TXN_READ_UNCOMMITTED, PDO::SQLSRV_TXN_READ_COMMITTED, 
         PDO::SQLSRV_TXN_REPEATABLE_READ, PDO::SQLSRV_TXN_SNAPSHOT, and 
         PDO::SQLSRV_TXN_SERIALIZABLE.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">TrustServerCertificate</code></dt>

       <dd>

        <p class="para">
         Specifies whether the client should trust (1 or <strong><code>true</code></strong>) or reject 
         (0 or <strong><code>false</code></strong>) a self-signed server certificate.
        </p>
       </dd>

      
      
       <dt>
<code class="literal">WSID</code></dt>

       <dd>

        <p class="para">
         Specifies the name of the computer for tracing.
        </p>
       </dd>

      
     </dl>

    </p>
   </div>


   <div class="refsect1 examples" id="refsect1-ref.pdo-sqlsrv.connection-examples">
    <h3 class="title">范例</h3>
    <p class="para">
     <div class="example" id="example-1101">
      <p><strong>示例 #1 PDO_SQLSRV DSN examples</strong></p>
      <div class="example-contents"><p>
       The following example shows how to connecto to a specified MS SQL Server database:
       <div class="example-contents">
<div class="cdata"><pre>
$c = new PDO(&quot;sqlsrv:Server=localhost;Database=testdb&quot;, &quot;UserName&quot;, &quot;Password&quot;);
</pre></div>
       </div>

       </p></div>
       <div class="example-contents"><p>
       The following example shows how to connect to a MS SQL Server database on 
       a specified port:
       <div class="example-contents">
<div class="cdata"><pre>
$c = new PDO(&quot;sqlsrv:Server=localhost,1521;Database=testdb&quot;, &quot;UserName&quot;, &quot;Password&quot;);
</pre></div>
       </div>

      </p></div>
      <div class="example-contents"><p>
       The following example shows how to connecto to a SQL Azure database with 
       server ID 12345abcde. Note that when you connect to SQL Azure with PDO, 
       your username will be UserName@12345abcde (UserName@ServerId).
       <div class="example-contents">
<div class="cdata"><pre>
$c = new PDO(&quot;sqlsrv:Server=12345abcde.database.windows.net;Database=testdb&quot;, &quot;UserName@12345abcde&quot;, &quot;Password&quot;);
</pre></div>
       </div>

      </p></div>
     </div>
    </p>
   </div>

  </div></div></div></body></html>